package cc.dao;

import cc.entity.User;

import org.apache.ibatis.annotations.*;

import org.springframework.stereotype.Repository;



import java.sql.SQLException;



/**

 * TODO

 *

 * @author My

 * @date 2021/10/11 17:11

 */

@Repository

public interface UserMapper {



    /**

     * 添加章

     *

     * @param user 章

     * @return

     */

    @Insert({"insert into t_user (id,name,password,sex,no,class_id) values (#{id},#{name},#{password},#{sex},#{no},#{classId})"})

    @Options(useGeneratedKeys = true, keyProperty = "id")

    int add(User user) throws SQLException;



    /**

     * 根据课程编号获取章列表

     *

     * @param courseIdPoReq 章列表

     * @return

     */

    @Select("select *  from tb_chapter where course_id = #{courseId} and is_delete = 0")

    @Results({

            @Result(property = "chapterId",column = "chapter_id"),

            @Result(property = "chapterTitle",column = "chapter_title"),

            @Result(property = "learningTime",column = "learning_time"),

    })

    User getChapterListByCourseId(User courseIdPoReq) throws SQLException;



    /**

     * 根据章节编号,查询该章下面的资源数量

     *

     * @param chapterIdPoReq

     * @return

     */

    @Select("select count(*) from tb_chapter_resource where chapter_id = #{chapterId}")

    Integer getResourceNumberOfChapter(User chapterIdPoReq) throws SQLException;



    /**

     * 删除章

     * @param chapterIdPoReq

     * @return

     */

    @Update("update tb_chapter set is_delete = 1 where chapter_id = #{chapterId}")

    int deleteChapterByChapterId(User chapterIdPoReq) throws SQLException;



    @Select("select id,name,password,sex,no,class_id as classId from t_user where id = #{id}")

    User getById(Integer id);



    @Select("select id,name,password,sex,no,class_id as classId from t_user where id = #{id}")

    User selectById(Integer id);



    @Update("update t_user set password = #{password} where id = #{id}")

    void updatePassword(User user);

}

